package com.dindang.maintenance.mvp.model;

import android.app.Application;

import com.dindang.maintenance.mvp.model.api.service.CommonService;
import com.dindang.maintenance.mvp.model.entity.BaseResponse;
import com.dindang.maintenance.mvp.model.entity.Repair;
import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;

import com.jess.arms.di.scope.ActivityScope;

import javax.inject.Inject;

import com.dindang.maintenance.mvp.contract.MaintainDetailsContract;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.Observable;


@ActivityScope
public class MaintainDetailsModel extends BaseModel implements MaintainDetailsContract.Model {
    @Inject
    Gson mGson;
    @Inject
    Application mApplication;

    @Inject
    public MaintainDetailsModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<BaseResponse<Repair.FlowDetail>> quertFlowDetail(Repair.FlowDetailParam param) {
        Observable<BaseResponse<Repair.FlowDetail>> base = mRepositoryManager.obtainRetrofitService(CommonService.class)
                .quertFlowDetail(param.id);
        return base;
    }

    @Override
    public Observable<BaseResponse> insertFlow(Repair.AddFlowParam param) {
        Map<String, String> map = new HashMap<>();
        if(null != param.cRemark && !"".equals(param.cRemark)){
            map.put("cRemark", param.cRemark);
        }
        Observable<BaseResponse> base = mRepositoryManager.obtainRetrofitService(CommonService.class)
                .insertFlow(param.cRepId,
                        param.cCorpid,
                        param.cCreator,
                        param.cCreatorid,
                        param.cStatus,
                        map);
        return base;
    }
}